﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Reflection;
using GaiNo.Core.Services;

namespace GaiNo.Core.Infrastructure
{
    /// <summary>
    /// Controller -> User [Dependency]
    /// </summary>
    public class UnityControllerFactory : DefaultControllerFactory
    {
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            IContainerAccessor containerAccessor = requestContext.HttpContext.ApplicationInstance as IContainerAccessor;
            Type controllerType = base.GetControllerType(requestContext, controllerName);
            if (controllerType != null)
                return containerAccessor.Container.Resolve(controllerType) as IController;
            return null;
        }
    }
}
